package natappvip.liujinliang.service.impl;

import natappvip.liujinliang.common.FileStatus;
import natappvip.liujinliang.dao.FileOperationDAO;
import natappvip.liujinliang.exception.FileIOException;
import natappvip.liujinliang.model.FileEle;
import natappvip.liujinliang.service.FileMetaDataService;

/**
 * @ClassName:  FileMetaDataDbServiceImpl   
 * @Despt: 数据库 文件元信息接口实现   
 * @Auth: Liujinliang 
 * @Date: 2018年7月29日 下午9:37:45
 */
public class FileMetaDataDbServiceImpl implements FileMetaDataService {
	private FileOperationDAO dao;
	
	@Override
	public String record(FileEle ele) {
		int res = dao.add(ele);
		if (res == -1) {
			throw new FileIOException("记录文件元信息失败");
		}
		return ele.toString();
	}
	
	@Override
	public String fetch(String uuid) {
		FileEle ele = dao.get(uuid);
		if (ele == null) {
			throw new FileIOException("获取文件元信息失败");
		}
		return ele.toString();
	}
	
	@Override
	public void remove(String uuid) {
		FileEle ele = dao.get(uuid);
		if (ele == null) {
			throw new FileIOException("获取文件元信息失败");
		}
		ele.setExisted(FileStatus.FILE_DELETED.getCode());
		int res = dao.del(uuid, ele);
		if (res != 0) {
			throw new FileIOException("删除文件元信息失败");
		}
	}

	@Override
	public String record(String mdata) {
		// TODO Auto-generated method stub
		return null;
	}
}
